/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.nju.software.greencreditsystem.action;

import cn.edu.nju.software.greencreditsystem.DTO.OutputWarningDTO;
import cn.edu.nju.software.greencreditsystem.domain.EnvironmentWarning;
import cn.edu.nju.software.greencreditsystem.domain.FinancialWarning;
import cn.edu.nju.software.greencreditsystem.factory.ServiceFactory;
import cn.edu.nju.software.greencreditsystem.service.WarningService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import java.util.Map;

/**
 * 作者：韩天
 * 创建时间：2011-8-22
 * 类描述：企业警告模块的action封装类
 */
public class EnterpriseWarningAction extends ActionSupport {
    private int enterpriseId;//企业的id
    private int fiancialUnread;//财务未读警告数
    private int environmentUnread;//环境未读警告数
    private List<FinancialWarning> financialList;//财务警告list
    private List<EnvironmentWarning> environmentList;//环境警告list
    private OutputWarningDTO warning;//用于前台显示的警告DTO
    private int warningId;//需读警告的id
    
    
    @Override
    /**
     * 方法描述：默认的执行方法，实现无条件跳转
     * param：
     * return：SUCCESS
     */
    public String execute(){
        return SUCCESS;
    }
    
    /**
     * 方法描述：企业跳转至查看警告界面
     * param：
     * return：SUCCESS
     */
    public String lookup_Warning(){
        //取得请求相关的ActionContext实例  
        ActionContext actionContext = ActionContext.getContext();
        Map session = actionContext.getSession();
        enterpriseId = Integer.valueOf((String) session.get("userId"));
        
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        this.fiancialUnread = ws.get_UnreadedFinancialCount(enterpriseId);
        this.environmentUnread = ws.get_UnreadedEnvironmentCount(enterpriseId);
        
        return SUCCESS;
    }
    
    /**
     * 方法描述：企业查看所有财务警告
     * param：
     * return：SUCCESS
     */
    public String lookup_AllFinancial(){
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        this.financialList = ws.get_AllFinancial(enterpriseId);
        
        return SUCCESS;
    }
    
    /**
     * 方法描述：企业查看所有环境警告
     * param：
     * return：SUCCESS
     */
    public String lookup_AllEnvironment(){
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        this.environmentList = ws.get_AllEnvironment(enterpriseId);
        
        return SUCCESS;
    }
    
    /**
     * 方法描述：企业查看所有未读财务警告
     * param：
     * return：SUCCESS
     */
    public String lookup_UnreadedFinancial(){
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        this.financialList = ws.getUnreadedFinancial(enterpriseId);
        
        return SUCCESS;
    }
    
    /**
     * 方法描述：企业查看所有未读环境警告
     * param：
     * return：SUCCESS
     */
    public String lookup_UnreadedEnvironment(){
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        this.environmentList = ws.getUnreadedEnvironment(enterpriseId);
        
        return SUCCESS;
    }

    /**
     * 方法描述：企业查看某条财务警告
     * param：
     * return：SUCCESS
     */
    public String lookup_A_Financial(){
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        this.warning = ws.getFinancialWarning(warningId, true);//true代表企业
        
        return SUCCESS;
    }
    
    /**
     * 方法描述：企业查看某条环境警告
     * param：
     * return：SUCCESS
     */
    public String lookup_A_Environment(){
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        this.warning = ws.getEnvironmentWarning(warningId, true);//true代表企业
        
        return SUCCESS;
    }
    
    
    /**
     * 方法描述：取得该企业未读财务警告数
     * param：
     * return：SUCCESS
     */
    public int getUnreadedFinancialCount(int eId){
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        return ws.get_UnreadedFinancialCount(eId);
    }
    
    /**
     * 方法描述：取得该企业未读环境警告数
     * param：
     * return：SUCCESS
     */
    public int getUnreadedEnvironmentCount(int eId){
        WarningService ws = ServiceFactory.getWarningServiceInstance();
        return ws.get_UnreadedEnvironmentCount(eId);
    }
    
    
    
    
    
    public int getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public List<EnvironmentWarning> getEnvironmentList() {
        return environmentList;
    }

    public void setEnvironmentList(List<EnvironmentWarning> environmentList) {
        this.environmentList = environmentList;
    }

    public int getEnvironmentUnread() {
        return environmentUnread;
    }

    public void setEnvironmentUnread(int environmentUnread) {
        this.environmentUnread = environmentUnread;
    }

    public int getFiancialUnread() {
        return fiancialUnread;
    }

    public void setFiancialUnread(int fiancialUnread) {
        this.fiancialUnread = fiancialUnread;
    }

    public List<FinancialWarning> getFinancialList() {
        return financialList;
    }

    public void setFinancialList(List<FinancialWarning> financialList) {
        this.financialList = financialList;
    }

    public OutputWarningDTO getWarning() {
        return warning;
    }

    public void setWarning(OutputWarningDTO warning) {
        this.warning = warning;
    }

    public int getWarningId() {
        return warningId;
    }

    public void setWarningId(int warningId) {
        this.warningId = warningId;
    }
}
